package com.thinkgem.jeesite.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.ListUtils;
import org.apache.ibatis.annotations.One;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.thinkgem.jeesite.modules.erp.dao.GoodsTypeDao;
import com.thinkgem.jeesite.modules.erp.entity.Compare;
import com.thinkgem.jeesite.modules.erp.entity.Department;
import com.thinkgem.jeesite.modules.erp.entity.Goods;
import com.thinkgem.jeesite.modules.erp.entity.GoodsType;
import com.thinkgem.jeesite.modules.erp.entity.OutAndInWarehouseOrder;
import com.thinkgem.jeesite.modules.erp.service.GoodsTypeService;
import com.thinkgem.jeesite.modules.erp.service.WareHouseService;
import com.thinkgem.jeesite.modules.erp.uitl.DBUtil;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:spring-context.xml" })
public class Demo {
	
	@Autowired
	private WareHouseService wareHouseService;
	@Autowired
	private GoodsTypeService goodsTypeService;
	
	@Autowired
	private GoodsTypeDao goodsTypeDao;
	
	@Test
    public void Test01() throws JsonProcessingException{
		Department dep = wareHouseService.queryAllDepsWorkers("1");
		ObjectMapper om = new ObjectMapper ();
		String depstr = om.writeValueAsString (dep);
		System.out.println(depstr);
		
    }
	@Test
    public void Test02() throws JsonProcessingException{
		Timestamp ts = new Timestamp(System.currentTimeMillis());   
        String tsStr = "2011-05-09 11:49:45";   
        try {   
        	System.out.println(ts);
            ts = Timestamp.valueOf(tsStr);   
            System.out.println(ts);   
        } catch (Exception e) {   
            e.printStackTrace();   
        }  
		
    }
	//查询个人订单
	@Test
    public void Test03() throws JsonProcessingException{
		OutAndInWarehouseOrder op=new OutAndInWarehouseOrder();
		op.setId(15);
		List<OutAndInWarehouseOrder> personalOrders = wareHouseService.getPersonalOrders(op);
		for(OutAndInWarehouseOrder a:personalOrders){
			System.out.println(a.getVerifier());
			List<Goods> goods = a.getGoods();
			for(Goods s:goods){
				System.out.println(s.getName());
			}
		}
    }
	@Test
	public void Test04() throws SQLException{
		Connection connection = DBUtil.getConnection();
		PreparedStatement ps = connection.prepareStatement("select * from InventoryClass");
		ResultSet rs = ps.executeQuery();
		
		while(rs.next()){
			 System.out.println(rs.getString("cInvCName"));  
		}
		DBUtil.release(connection, ps, rs);
	}
	
	@Test
	public void Test05() throws Exception{
		Map<String,Object>map=new HashMap<String,Object>();
		map.put("fatherGrade", 1);
		map.put("sonGrade", 2);
		List<GoodsType> list = goodsTypeService.parentQueryGoodsTree(map);
		for (GoodsType g : list) {
			System.out.println(g.getText());
		}
	}
	@SuppressWarnings("null")
	@Test
	public void Test06() throws IOException{
		InputStream in = this.getClass().getClassLoader().getResourceAsStream("a.txt");
		InputStreamReader isr=new InputStreamReader(in, "UTF-8");
		BufferedReader bufferedReader = new BufferedReader(isr);
		String lineTxt=null;
		StringBuilder sb=new StringBuilder();
		while((lineTxt = bufferedReader.readLine()) != null){
			sb.append(lineTxt);
        }
		String[] split = sb.toString().split(",");
		System.out.println(split.length);
	}
	
	@Test
	public void Test07(){
		List<String> one=new ArrayList<String>();
		
		one.add("1");
		one.add("2");
		one.add("3");
		List<String> two=new ArrayList<String>();
		two.add("1");
		two.add("5");
		two.add("6");
		one.removeAll(two); //one-two
		System.out.println(one.size());
		for (String string : one) {
			System.out.println(string);
		}
	}
	@Test
	public void Test08(){
		Compare one=new Compare("1", "one");
		Compare two=new Compare("2", "three");
		List<Compare> listone=new ArrayList<Compare>();
		listone.add(one);
		listone.add(two);
		List<Compare> listtwo=new ArrayList<Compare>();
		
		Compare three=new Compare("2", "two");
		listtwo.add(three);
		listtwo.add(one);
		
		@SuppressWarnings("unchecked")
		List<Compare> subtract = ListUtils.subtract(listone, listtwo);
		for (Compare compare : subtract) {
			System.out.println(compare.getName());
		}
		System.out.println(subtract.size());
	}
	@Test
	public void Test09() throws Exception{
		List<Map<String, Object>> result = goodsTypeService.queryInsert();
		for (Map<String, Object> map : result) {
			System.out.println(map.get("cInvCode")+":"+map.get("cInvName")+":"+map.get("cInvCCode"));
		}
	}
	
	@Test
	public void Test10() throws Exception{
		List<String> result = goodsTypeService.queryDelete();
		for (String map : result) {
			System.out.println(map);
		}
	}
	
	@Test
	public void Test11() throws Exception{
		List<Compare> result = goodsTypeService.queryUpdate();
		for (Compare map : result) {
			System.out.println(map.getCode()+":"+map.getName());
		}
	}
	
	@Test
	public void Test12(){
		Compare one=new Compare("4050400126","钣金 湿幕弯头与空调对接 2200mm*860mm*520mm [温州联通富春江路机房]");
		Compare two=new Compare("4050400129", "钣金 湿幕新风过滤段 [温州湿幕]");
		Compare three=new Compare("4050400121", "机箱零部件 潜水泵DB-D555安装架");
		Compare four=new Compare("4050400120", "机箱零部件 进水管扣");
		
		Compare error=new Compare("4050400120", "机箱零部件 进水管扣2");
		
		Compare redundant=new Compare("10000001", "成套-动力监控");
		List<Compare> listone=new ArrayList<Compare>();
		
		listone.add(one);
		listone.add(two);
		listone.add(three);
		listone.add(four);
		
		List<Compare> listtwo=new ArrayList<Compare>();
		listtwo.add(one);
		listtwo.add(error);
		listtwo.add(redundant);
		
		@SuppressWarnings("unchecked")
		List<Compare> subtract = ListUtils.subtract(listone, listtwo);
		System.out.println("长度："+subtract.size());
		for (Compare compare : subtract) {
			System.out.println(compare.getName()+compare.getCode());
		}
	}
	
	
	@Test
	public void Test13(){
		Compare one=new Compare("0010000005", "一体化采集器 ADSL组网成套设备 [要ADSL模块]]");
		Compare two=new Compare("0010000002", "动力环境监控成套(移动公司干节点监控)不带空调转换模块");
		List<Compare>list=new ArrayList<Compare>();
		list.add(one);
		list.add(two);
		goodsTypeDao.upateInventory(list);
		
	}
	
	
}
